import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:get/get.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:yp/helper.dart';

import '../logic.dart';
import '../state.dart';

class TurntableAwardView extends StatelessWidget {
  TurntableAwardView({Key key}) : super(key: key);
  final logic = Get.find<TurntableAwardLogic>();
  final TurntableAwardState state = Get.find<TurntableAwardLogic>().state;
  //
  @override
  Widget build(BuildContext context) {
    return FlutterEasyLoading(
        child: Container(
            color: Colors.white,
            child: SmartRefresher(
              controller: state.refreshCtrl,
              onLoading: logic.onLoading,
              onRefresh: logic.onRefresh,
              enablePullUp: true,
              child: ListView.separated(
                  itemBuilder: (context, index) {
                    var item = state.awardList[index];
                    return InkWell(
                      onTap: () {
                        logic.awardItemClick(item);
                      },
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Row(
                                children: [
                                  Container(
                                    height: setWidth(28),
                                    width: setWidth(8),
                                    decoration: BoxDecoration(
                                        borderRadius:
                                            BorderRadiusDirectional.circular(
                                                setWidth(4)),
                                        gradient: LinearGradient(
                                            begin: Alignment.topCenter,
                                            end: Alignment.bottomCenter,
                                            colors: [
                                              Color(0xffF5515F),
                                              Color(0xff9F041B)
                                            ])),
                                  ),
                                  SizedBox(
                                    width: setWidth(20),
                                  ),
                                  Text(
                                    '奖品名称',
                                    style: TextStyle(
                                        color: Color(0xff222222),
                                        fontSize: setWidth(32)),
                                  )
                                ],
                              ),
                              InkWell(
                                child: item['receive_flag'] == 1
                                    ? Text(
                                        '已领取',
                                        style: TextStyle(
                                            color: Color(0xff999999),
                                            fontSize: setWidth(32)),
                                      )
                                    : Text('未领取',
                                        style: TextStyle(
                                            color: Color(0xffF5A623),
                                            fontSize: setWidth(32))),
                              )
                            ],
                          ),
                          Padding(
                            padding: EdgeInsets.only(
                                left: setWidth(28), top: setWidth(20)),
                            child: Text(
                              item['reward_description'],
                              style: TextStyle(
                                  color: Color(0xff333333),
                                  fontSize: setWidth(34)),
                            ),
                          ),
                          Padding(
                            padding: EdgeInsets.symmetric(
                                horizontal: setWidth(28),
                                vertical: setWidth(20)),
                            child: Text(
                              '兑换期限：' +
                                  item['exchange_begin_dtme'] +
                                  '至' +
                                  item['exchange_end_dtme'],
                              style: TextStyle(
                                  color: Color(0xff999999),
                                  fontSize: setWidth(24)),
                            ),
                          )
                        ],
                      ),
                    );
                  },
                  separatorBuilder: (context, index) => Divider(
                        color: Color(0xffefefef),
                      ),
                  itemCount: state.awardList?.length ?? 0),
            )));
  }

  Widget _getCell(String title, String content) {
    return Column(
      children: [
        Row(
          children: [
            Container(
              height: setWidth(28),
              width: setWidth(8),
              decoration: BoxDecoration(
                  borderRadius: BorderRadiusDirectional.circular(setWidth(4)),
                  gradient: LinearGradient(
                      begin: Alignment.topCenter,
                      end: Alignment.bottomCenter,
                      colors: [Color(0xffF5515F), Color(0xff9F041B)])),
            ),
            SizedBox(
              width: setWidth(20),
            ),
            Text(
              title,
              style:
                  TextStyle(color: Color(0xff222222), fontSize: setWidth(32)),
            )
          ],
        ),
        SizedBox(
          height: setWidth(20),
        ),
        Text(
          content,
          style: TextStyle(color: Color(0xff666666), fontSize: setWidth(26)),
        )
      ],
    );
  }
}
